//
//  MainViewController.m
//  CWNotificationDemo
//
//  Created by Cezary Wojcik on 11/15/13.
//  Copyright (c) 2013 Cezary Wojcik. All rights reserved.
//

#import "MainViewController.h"
#import "CWStatusBarNotification.h"

@interface MainViewController ()

@end

@implementation MainViewController

@synthesize lblDuration, txtNotificationMessage, sliderDuration;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.title = @"CWStatusBarNotification";
    [self updateDurationLabel];
    UIFont *font = [UIFont boldSystemFontOfSize:10.0f];
    NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    [self.segFromStyle setTitleTextAttributes:attributes forState:UIControlStateNormal];
    [self.segToStyle setTitleTextAttributes:attributes forState:UIControlStateNormal];

    // initialize CWNotification
    self.notification = [CWStatusBarNotification new];

    // set default blue color (since iOS 7.1, default window tintColor is black)
    self.notification.notificationLabelBackgroundColor = [UIColor colorWithRed:0.0 green:122.0 / 255.0 blue:1.0 alpha:1.0];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
    [self.view addGestureRecognizer:tap];
}

- (void)tapGesture:(UITapGestureRecognizer *)tap {
    [self.txtNotificationMessage resignFirstResponder];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)updateDurationLabel
{
    self.lblDuration.text = [NSString stringWithFormat:@"%f seconds", self.sliderDuration.value];
}

- (IBAction)sliderDurationChanged:(UISlider *)sender
{
    [self updateDurationLabel];
}

# pragma mark - show notification

- (void)setupNotification
{
    self.notification.notificationAnimationInStyle = self.segFromStyle.selectedSegmentIndex;
    self.notification.notificationAnimationOutStyle = self.segToStyle.selectedSegmentIndex;
    self.notification.notificationStyle = self.notificationStyle.selectedSegmentIndex == 0 ?
        CWNotificationStyleStatusBarNotification : CWNotificationStyleNavigationBarNotification;
}

- (IBAction)btnShowNotificationPressed:(UIButton *)sender
{
    [self.view endEditing:YES];
    [self setupNotification];
    self.notification.notificationLabelHeight = 0;
    [self.notification displayNotificationWithMessage:[NSString stringWithFormat:@"%@", self.txtNotificationMessage.text] forDuration:self.sliderDuration.value];
}

- (IBAction)btnShowCustomNotificationPressed:(UIButton *)sender {
    [self.view endEditing:YES];

    [self setupNotification];
    UIView *view = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil options:nil][0];

    self.notification.notificationLabelHeight = 40;
    [self.notification displayNotificationWithView:view forDuration:self.sliderDuration.value];
}

@end
